package com.xuef.dxf.namenode.server;

import java.io.IOException;

public class NameNode {
    private volatile boolean shouldRun;
    /**
     * 负责管理元数据的核心文件
     */
    private FSNameSystem fsNameSystem;
    private DataNodeManager dataNodeManager;
    private NameNodeRpcServer nameNodeRpcServer;

    public NameNode(){
        this.shouldRun = true;
    }
    public void initialize(){
        //组件在一处初始化，向别处传递
        this.fsNameSystem = new FSNameSystem();
        this.dataNodeManager = new DataNodeManager();

        this.nameNodeRpcServer = new NameNodeRpcServer(fsNameSystem, dataNodeManager);
        try {
            dataNodeManager.startHeartbeatMonitor();
            this.nameNodeRpcServer.start();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    private void run(){
        try{
            while(shouldRun){
                Thread.sleep(10*1000);
            }
        }catch (Exception e){

        }
    }

    public static void main(String[] args) {
        NameNode nameNode = new NameNode();
        nameNode.initialize();
        nameNode.run();
    }
}
